package cn.lf.android.lawfirm.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import java.util.Stack;

import cn.lf.android.lawfirm.home.modle.UserInfo;
import cn.lf.android.lawfirm.login.UserAccount;


/**
 * @author
 */
public class SPUtil {

    private SharedPreferences sp;

    public SPUtil(Context context) {
        sp = context.getSharedPreferences("LawFirm", Context.MODE_PRIVATE);
    }

    /**
     * 存储账号信息
     *
     * @param account
     */
    public void setAccountInfo(UserAccount account) {
        Editor edit = sp.edit();
        edit.putString("UserName", account.getUserName());
        edit.putString("Password", account.getPassword());
        edit.putString("userId", account.getUserId());
        edit.commit();
    }

    /**
     * 获取账号信息
     *
     * @return
     */
    public UserAccount getUserAccount() {
        UserAccount account = new UserAccount();
        account.setUserName(sp.getString("UserName", ""));
        account.setPassword(sp.getString("Password", ""));
        account.setUserId(sp.getString("userId", ""));
        return account;
    }

    /**
     * 存储账号accessToken
     *
     * @param accessToken
     */
    public void setAccessToken(String accessToken) {
        Editor edit = sp.edit();
        edit.putString("accessToken", accessToken);
        edit.commit();
    }

    /**
     * 获取账号accessToken
     *
     * @return accessToken
     */
    public String getAccessToken() {
        sp.getString("accessToken", "");
        return sp.getString("accessToken", "");
    }

    /**
     * 存储个人信息
     */
    public void setUserInfo(UserInfo userInfo) {
        Editor edit = sp.edit();
        edit.putString("userName", userInfo.userName);
        edit.putString("deptName", userInfo.deptName);
        edit.putString("roleName", userInfo.roleName);
        edit.putString("accountPicture", userInfo.accountPicture);
        edit.commit();
    }

    /**
     * 获取个人信息
     *
     * @return accessToken
     */
    public UserInfo getUserInfo() {
        UserInfo userInfo = new UserInfo();
        userInfo.userName = sp.getString("userName", "");
        userInfo.deptName = sp.getString("deptName", "");
        userInfo.roleName = sp.getString("roleName", "");
        userInfo.accountPicture = sp.getString("accountPicture", "");
        return userInfo;
    }

}
